<?php
/**
 * @link http://framework.zend.com/manual/en/zend.form.elements.html
 */
class Areal_Validate_OldPassword extends Zend_Validate_Abstract
{
    const NOT_MATCH = 'notMatch';

    protected $_messageTemplates = array(
        self::NOT_MATCH => 'Old password is incorrect'
    );

    protected $_user;

    public function __construct(Default_Model_User $user)
    {
        $this->_user = $user;
    }

    public function isValid($value, $context = null)
    {
        $userCopy = clone $this->_user;
        $userCopy->password = $value;
        if ($this->_user != $userCopy){
            $this->_error(self::NOT_MATCH);
            return false;
        }
        return true;
    }
}